package com.scau.wuwei.library_system.core.controller;

import com.scau.wuwei.library_system.core.bean.BookInfo;
import com.scau.wuwei.library_system.core.bean.BookInfoQuery;
import com.scau.wuwei.library_system.core.service.BookInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
@RequestMapping(value = "/queryBook")
public class BookInfoController {
    @Autowired
    private BookInfoService bookInfoService;

    @RequestMapping(value = "/findBookNoQuery")
    public String findBookNoQuery(ModelMap modelMap, @RequestParam(value = "page", defaultValue = "0") Integer page,
                                  @RequestParam(value = "size", defaultValue = "50") Integer size) {
        Page<BookInfo> datas = bookInfoService.findBookNoCriteria(page, size);
        modelMap.addAttribute("datas", datas);

        return "bookNoQuery";
    }

    @RequestMapping(value = "/findBookQuery")
    public String findBookQuery(ModelMap modelMap, @RequestParam(value = "page", defaultValue = "0") Integer page,
                                @RequestParam(value = "size", defaultValue = "50") Integer size,
                                BookInfoQuery bookInfoQuery) {
        Page<BookInfo> datas = bookInfoService.findBookCriteria(page, size, bookInfoQuery);
        modelMap.addAttribute("datas", datas);

        return "bookQuery";
    }
}
